// initialise plugins

jQuery(document).ready(function() {
	
	// Expand Panel
	jQuery('#slidingpanel').stop().animate({'marginLeft':'-220px'},0);

	jQuery('#open').click(function () {
		jQuery('#slidingpanel').click(
			function () {
				$('#panel, #toggle',$(this)).stop().animate({'marginLeft':'220px'},500);
			}
		);
	});
	
	jQuery('#close').click(function () {
		jQuery('#slidingpanel').click(
			function () {
				$('#panel, #toggle',$(this)).stop().animate({'marginLeft':'0px'},500);
			}
		);
	});
	
	// Switch buttons from "Open" to "Close" on click
	jQuery("#toggle div").click(function () {
		jQuery("#toggle div").toggle();
	});		
	
	// Flying panel Up/Down
	var offset = $("#slidingpanel").offset();
	var topPadding = 50;
	$(window).scroll(function() {
		if ($(window).scrollTop() > offset.top) {
			$("#slidingpanel").stop().animate({
				marginTop: $(window).scrollTop() - offset.top + topPadding
			});
		} else {
			$("#slidingpanel").stop().animate({
				marginTop: 0
			});
		};
	});
	
	// Call jQuery Uniform for Select
	//jQuery("#panel select").uniform();
	
	// Call jQuery to add a class for header background
	jQuery('.header_full').addClass('sample_01');
	
	// Call jQuery mColorPicker
	jQuery('#bgcolor').bind('change', function () {
		jQuery('body').css('background-color', jQuery(this).val());
	});
	
	// Call jQuery mColorPicker
	jQuery('#headercolor').bind('change', function () {
		jQuery('.header_full').css('background-color', jQuery(this).val()).removeClass('sample_01 sample_02 sample_03 sample_04 sample_05 sample_06 sample_07 sample_08 sample_09 sample_10 sample_11 sample_12 sample_13 sample_14 sample_15 sample_16 sample_17 sample_18 sample_19 sample_20 active');
	});
	
	// Set Samples
	jQuery('.samples a').click(function(event) { 
		jQuery('.header_full, .samples a').removeClass('sample_02 sample_03 sample_04 sample_05 sample_06 sample_07 sample_08 sample_09 sample_10 sample_11 sample_12 sample_13 sample_14 sample_15 sample_16 sample_17 sample_18 sample_19 sample_20 active');
		jQuery('.header_full').addClass(jQuery(this).attr('rel'));
		jQuery(this).addClass('active');
		return false;
	});
	
	// Reset Panel
	jQuery('a.btn_reset').click(function(event) { 
		jQuery('.header_full, .samples a').removeClass('sample_02 sample_03 sample_04 sample_05 sample_06 sample_07 sample_08 sample_09 sample_10 sample_11 sample_12 sample_13 sample_14 sample_15 sample_16 sample_17 sample_18 sample_19 sample_20 active');
		jQuery('body').removeAttr('style');
		jQuery('.header_full').addClass('sample_01');
		return false;
	});

	
});
	

// Font Chooser
jQuery(document).ready(function(){
	jQuery("#content_fonts").change(onSelectChangeContent);
	jQuery('#content_fonts option:not(option:first, option:last)').each(function(){
		jQuery(this).css('font-family', jQuery(this).text());
	});
});

function onSelectChangeContent(){
	var selected = jQuery("#content_fonts option:selected");		
	var output = "";
	if(selected.val() != 0){
		output = selected.text();
	}
	jQuery('body').css('font-family', output);
}